<template>
    <div class="set-up">
        <h1>设置页面</h1>
        <hr>
        <van-button type="danger" @click="exit" v-if="userInfo.id">退出</van-button>
    </div>
</template>


<script setup>
import { computed, onMounted, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import { showToast} from 'vant'
import { addCart } from '../../apis/loginApi'
let router = useRouter()
let store  = useStore()

let cartList = computed(()=>{
    return store.getters['cartModule/getCartList']
})
let userInfo = computed(()=> store.getters['loginModule/getUserInfo'])

let info = reactive({
    phone:userInfo.value.phone,
    cartList:cartList.value
})
// onMounted(()=>{
//     console.log(info);
// })


async function exit(){

    let result = await addCart(info)
    // console.log('result',result.data)
    store.commit('loginModule/changeUserInfo',{})
    store.commit('cartModule/emptyCartList')
    store.commit('loginModule/clearAddr')
    showToast('退出成功');
    router.push('/mine')
}


</script>


<style lang="less" scoped>
button{
    width: 100%;
}
</style>